//delete//
const getFieldPageList = require("../mock/server/getFieldPageList");
const getFieldList = require("../mock/server/getFieldList");
const getFieldDetail = require("../mock/server/getFieldDetail");
const exportField = require("../mock/server/exportField");
const statusCode = require('../util/status-code')
const Utils = require("../util/utils")
//delete//
class BuryPointFieldController {
    /**
     * 创建信息
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async create(ctx) {
        let req = JSON.parse(ctx.request.body);
        if (req.fieldAlias && req.fieldType && req.fieldLength && req.fieldDesc) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('创建点位字段成功', '')
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('创建点位字段失败，请求参数不能为空！')
        }
    }

    /**
     * 详情信息
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async detail(ctx) {
        const param = Utils.parseQs(ctx.request.url)
        let id = param.id;
        if (id) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('获取点位字段成功', getFieldDetail)
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('获取点位字段失败，请求参数不能为空！')
        }
    }

    /**
     * 更新
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async update(ctx) {
        let req = JSON.parse(ctx.request.body);
        let id = req.id;
        if (req) {    
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('更新信息成功！', getFieldDetail);
        } else {
    
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('更新信息失败！')
        }
    }
  
    static async delete(ctx) {
        let param = JSON.parse(ctx.request.body);
        // 删除前，先检查所有点位仓库是否有该字段
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', "")
    
    }
    
    static async exportField(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', exportField)
    
    }

    /**
     * page
     * @param 
     * 
     */
    static async getPageList(ctx) {
        let req = ctx.request.body
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getFieldPageList)
    }

    static async getList(ctx) {
        let req = ctx.request.body
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getFieldList)
    }

    static async getListByPointId(ctx) {
        let req = ctx.request.body
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getFieldList)
    }

    static async getAllList(ctx) {
        const res = getFieldList
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', res)
    }
}
//exports//
module.exports = BuryPointFieldController
//exports//